package com.sfc.spiderweb.rest;

import com.sfc.spiderweb.service.PlatformRdpUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 李振伟(Earl Li)
 * @title: AmzonController
 * @projectName spider-web
 * @description: ${description}
 * @date 2020/3/313:37
 */
@Api(tags = "爬虫定时任务接口")
@RestController
@RequestMapping(value = "/amazon")
@Slf4j
public class AmzonController {

    @Resource
    private PlatformRdpUserService platformRdpUserService;


    @ApiOperation(notes = "amazon账号违规数据发送邮件", value = "")
    @GetMapping("/amazonViolationDataSendMail")
    public void sendAmazonViolationData() {
        log.info("amazonViolationDataSendMail开始");
        try {
            platformRdpUserService.sendAmazonViolationData();
        } catch (Exception e) {
            e.printStackTrace();
            RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
            HttpServletResponse resp = ((ServletRequestAttributes) requestAttributes).getResponse();
            resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        } finally {
            log.info("amazonViolationDataSendMail结束");
        }
    }

    @ApiOperation(notes = "amazon上传发票程序发送邮件", value = "")
    @GetMapping("/amazonUploadInvoiceSendMail")
    public void amazonUploadInvoiceSendMail() {
        log.info("amazonUploadInvoiceSendMail开始");
        try {
            platformRdpUserService.sendAmazonAmazonUploadInvoice();
        } catch (Exception e) {
            e.printStackTrace();
            RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
            HttpServletResponse resp = ((ServletRequestAttributes) requestAttributes).getResponse();
            resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        } finally {
            log.info("amazonUploadInvoiceSendMail结束");
        }
    }
}
